using CoreManager.MessageQueue.Models;

namespace CoreManager.MessageQueue.Services;

/// <summary>
/// Kafka生产者服务接口
/// </summary>
public interface IKafkaProducerService
{
    /// <summary>
    /// 发送消息
    /// </summary>
    /// <param name="topic">主题</param>
    /// <param name="message">消息</param>
    /// <param name="key">消息键（可选）</param>
    /// <param name="cancellationToken">取消令牌</param>
    /// <returns>发送结果</returns>
    Task<MessageSendResult> SendMessageAsync(string topic, KafkaMessage message, string? key = null, CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 发送泛型消息
    /// </summary>
    /// <typeparam name="T">消息数据类型</typeparam>
    /// <param name="topic">主题</param>
    /// <param name="data">消息数据</param>
    /// <param name="key">消息键（可选）</param>
    /// <param name="cancellationToken">取消令牌</param>
    /// <returns>发送结果</returns>
    Task<MessageSendResult> SendMessageAsync<T>(string topic, T data, string? key = null, CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 批量发送消息
    /// </summary>
    /// <param name="topic">主题</param>
    /// <param name="messages">消息列表</param>
    /// <param name="cancellationToken">取消令牌</param>
    /// <returns>发送结果列表</returns>
    Task<List<MessageSendResult>> SendMessagesAsync(string topic, IEnumerable<KafkaMessage> messages, CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 释放资源
    /// </summary>
    void Dispose();
}
